<?php

namespace app\api\Logic\Campusclass;

use app\api\model\CampusClassCourseDateModel;
use think\db\exception\DataNotFoundException;
use think\db\exception\ModelNotFoundException;
use think\exception\DbException;

//班课接口
class ClassCourseLogic
{
    /**
     * 获取班课详情
     * @param $classCourseDateId
     * @return array
     * @throws DataNotFoundException
     * @throws DbException
     * @throws ModelNotFoundException
     */
    public function getInfo($classCourseDateId){
        $info = CampusClassCourseDateModel::where('id',$classCourseDateId)
            ->with([
                'classInfo' => function ($query) {
                    $query->withField('id,name,class_size');
                },
                'classRoom' => function ($query) {
                    $query->withField('id,name');
                },
                'teacherInfo' => function ($query) {
                    $query->withField('id,username,nickname')
                        ->where('level',2);
                }
            ])
            ->field('id,a_id,class_id,week,start_time,end_time,teacher_id,classroom_id,status,create_time,sign_time,sign_teacher')
            ->find();
        return objToArray($info) ?? [];
    }
}
